import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Login',
    component: () => import('../components/login.vue')
  },
  {
    path: '/reg',
    name: 'Register',
    component: () => import('../components/register.vue')
  },
  {
    path: '/commodity',
    name: 'Commodity',
    alias: ['/goods'],
    // redirect: '/commodity/menu',
    // redirect: {
    //   path: '/commodity/menu'
    // },
    redirect: to => {
      console.log('to :>> ', to);
      return {
        path: '/commodity/menu',
        query: {
          name: '小十'
        }
      }
    },
    component: () => import('../components/commodity.vue'),
    children: [
      {
        path: 'menu',
        name: 'CommodityMenu',
        components: {
          default: () => import('../components/menu.vue')
          /**
           * name1: () => import('../components/name1.vue')
           * <router-view name="name1"></router-view>
           */
        }
      },
      {
        path: 'address',
        name: 'CommodityAddress',
        component: () => import('../components/address.vue')
      }
    ]
  },
  {
    path: '/commodity-detail',
    name: 'CommodityDetail',
    component: () => import('../components/commodityDetail.vue')
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router
